package com.wbp.cms.qatest.dao;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;

import com.wbp.cms.client.customer.domain.CustomerDO;
import com.wbp.cms.client.customer.query.CustomerQuery;
import com.wbp.cms.client.util.DateUtils;
import com.wbp.cms.core.customer.dao.CustomerDAO;
import com.wbp.cms.qatest.BaseTest;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月6日 下午10:46:33
 */
public class CustomerDAOTest extends BaseTest {

  @Resource
  private CustomerDAO customerDAO;


  @Test
  public void test001() {

    System.out.println("test001");
  }

  @Test
  public void test_insert() {
    CustomerDO customerDO = new CustomerDO();
    customerDO.setNickName("大白");
    customerDO.setImage("http://alibaba-inc.com/test/1.png");
    customerDO.setUserName("lihctest001");
    customerDO.setPwd("00009");

    System.out.println(customerDAO.insertCustomer(customerDO) == 1);
  }

  @Test
  public void test_insert详细信息() {
    CustomerDO customerDO = new CustomerDO();
    customerDO.setNickName("小树");
    customerDO.setImage("http://alibaba-inc.com/test/1.png");
    customerDO.setUserName("lihctest002");
    customerDO.setPwd("00009");
    customerDO.setBirthday(new Date(System.currentTimeMillis() + 1000 * 36000).toString());
    customerDO.setIdCard("420983198706259087");
    customerDO.setEmail("493919512@qq.com");
    customerDO.setGender(1);
    customerDO.setRealName("lihc");
    customerDO.setRecommendUserName("厉鸿超11");
    customerDO.setUserId(2L);
    customerDO.setGender(1);
    customerDO.setAddress("淅江杭州黄龙时代中心A座");
    customerDO.setCustomerLevel(1);
    customerDO.setMobileNumber("18971612470");
    customerDO.setType(1);
    try {
      customerDO.setBirthday(DateUtils.parse("1987-06-26", DateUtils.ISO_DATE_FORMAT).toString());
    } catch (ParseException e) {
      e.printStackTrace();
    }
    System.out.println(customerDAO.insertCustomer(customerDO) == 1);
  }

  @Test
  public void test_query_01() {

    CustomerQuery customerQuery = new CustomerQuery();
    customerQuery.setAddress("浙江");
    List<CustomerDO> list = customerDAO.queryCustomer(customerQuery);
    System.out.println(list);
  }

  @Test
  public void test_update_更新001() {

    CustomerDO customer = customerDAO.queryCustomerById(2L);
    if (customer != null) {
      customer.setAddress("浙江杭州文二路兴达宛4-101");
      customer.setPwd("00007");
      customer.setBusinessLicense("222222222");
      customer.setLegalPerson("张三");
      customer.setGender(2);
      customer.setNickName("nick-name");
      customer.setRealName("real-name");
      customer.setCustomerLevel(2);
      customer.setCustomerLevelLogo("http://111111/2222/33.png");

      System.out.println(customerDAO.updateCustomer(customer) == 1);
    }
  }

}
